<template>
	<view class="container hideToShow">
		<!-- <view class="header">
			<text class="header-text">企业营业执照识别</text>
		</view> -->
		<view class="form-warp">
			<uni-forms class="form" labelPosition="top">
				<!-- 企业营业执照 -->
				<!-- <uni-file-picker class="image-picker" file-mediatype="image" mode="grid" file-extname="png,jpg"
					:limit="1" :image-styles="imageStyle" @success="imgSuccess" @fail="imgFail"></uni-file-picker> -->
				<!-- 统一社会信用代码 -->
				<uni-forms-item class="form-item" label="统一社会信用代码" label-width="200" required>
					<uni-easyinput v-model="company.code" placeholder="请输入统一社会信用代码" :inputBorder="false" />
				</uni-forms-item>
				<!-- 企业名称 -->
				<uni-forms-item class="form-item" label="企业名称" label-width="200" required>
					<uni-easyinput v-model="company.c_name" placeholder="请输入企业名称" :inputBorder="false" />
				</uni-forms-item>
				<!-- 注册地址 -->
				<uni-forms-item class="form-item1" label="注册地址" label-width="200" required>
					<uni-easyinput v-model="company.reg_address" type="textarea" placeholder="请输入注册地址" />
				</uni-forms-item>
				<!-- 注册资金(万元) -->
				<uni-forms-item class="form-item" label="注册资金" label-width="200" required>
					<uni-easyinput v-model="company.money" placeholder="请输入注册资金" :inputBorder="false" />
				</uni-forms-item>
				<!-- 法人/负责人 -->
				<uni-forms-item class="form-item" label="法人/负责人" label-width="200" required>
					<uni-easyinput v-model="company.manager" placeholder="请输入法人/负责人" :inputBorder="false" />
				</uni-forms-item>
				<!-- 法人/负责人联系电话 -->
				<uni-forms-item class="form-item" label="法人/负责人联系电话" label-width="200" required>
					<uni-easyinput v-model="company.phoneNum" placeholder="请输入法人/负责人联系电话" :inputBorder="false" />
				</uni-forms-item>
				<!-- 企业邮箱 -->
				<uni-forms-item class="form-item" label="企业邮箱" label-width="200" required>
					<uni-easyinput v-model="company.email" placeholder="请输入企业邮箱" :inputBorder="false" />
				</uni-forms-item>
				<!-- 经营范围 -->
				<uni-forms-item class="form-item1" label="经营范围" label-width="200" required>
					<uni-easyinput v-model="company.scope" type="textarea" placeholder="请输入经营范围" />
				</uni-forms-item>
				<!-- 企业联系地址 -->
				<uni-forms-item class="form-item1" label="企业联系地址" label-width="200" required>
					<uni-easyinput v-model="company.real_address" type="textarea" placeholder="请输入联系地址" />
				</uni-forms-item>
			</uni-forms>
			<button class="next-btn" type="default" @tap="upload()">提交</button>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			timer: null,
			// 图片上传
			imageValue: [],
			imageStyle: {
				height: 170,
				width: 500,
				border: {
					width: '1px',
					style: 'solid',
					radius: '1%'
				}
			},

			// 企业信息
			company: {
				code: '', //信用代码
				c_name: '', //企业名称
				reg_address: '', //注册地址
				money: '', //注册资金
				manager: '', //法人/负责人
				phoneNum: '', //法人/负责人联系电话
				email: '', //企业邮箱
				scope: '', //经营范围
				real_address: '' //企业联系地址
			}
		};
	},
	onHide() {
		if (this.timer) clearTimeout(this.timer);
	},
	methods: {
		// 图片上传成功
		imgSuccess() {
			this.$until.showToast('上传成功');
		},
		// 图片上传失败
		imgFail() {
			this.$until.showToast('上传失败', 'error');
		},
		// 信息上传，进行下一步
		upload() {
			// 校验的企业信息
			let checkCompany = this.company;
			if (this.$until.checkCompany(checkCompany)) {
				const callback = () => {
					uni.showLoading({
						mask: true,
						title: '提交中...'
					});
					uniCloud.callFunction({
						name: 'regist',
						data: {
							type: 'company',
							...checkCompany
						},
						success: res => {
							uni.hideLoading();
							let data = res.result;
							if (data.success) {
								this.$until.showToast(data.message);
								this.timer = setTimeout(() => {
									uni.redirectTo({
										url: '/pages/user/login'
									});
								}, 1500);
							} else this.$until.showToast(data.message);
						},
						fail: err => {
							this.$until.showToast('注册失败' + JSON.stringify(err));
						}
					});
				};
				this.$debounce(callback, 500);
			}
		}
	}
};
</script>

<style lang="less" scoped>
.container {
	width: 100%;
	min-height: 100vh;
	background-color: #fff;

	.header {
		width: 100%;
		height: 60rpx;
		background-color: #fff;
		padding: 30rpx 0;
		margin-bottom: 20rpx;
		font-size: 30rpx;
		font-weight: bold;
		color: #333;
		line-height: 60rpx;

		.header-text {
			border-left: 6rpx solid #48e7a5;
			padding-left: 20rpx;
		}
	}

	.form-warp {
		width: 100%;
		padding: 20rpx 48rpx;
		box-sizing: border-box;
		.image-picker {
			width: 100%;
			height: 340rpx;
		}

		/deep/.is-required {
			margin-right: 8rpx;
		}

		.form-item {
			border-bottom: 2rpx solid #e8e8e8;
		}
	}

	.next-btn {
		color: #fff;
		margin-bottom: 44rpx;
		border-radius: 46rpx;
		background-color: #04d48e;
	}
}
</style>
